package com.ktjiaotu.examples;

import com.ktjiaotu.pojo.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * @Author: DABINGCHNEGJIAO
 * @CreateTime: 2025-06-04
 * @Description:
 * @Version: 1.0
 */
public class TypeInfo {
    public static void main(String[] args) {
        Class ps = Person.class;
        System.out.println("类名:" + ps.getSimpleName());
        System.out.println("全类名:" + ps.getCanonicalName());
        System.out.println("父类:" + ps.getSuperclass().getName());
        System.out.println("实现的接口:" + ps.getInterfaces()[0]);
        int modifiers = ps.getModifiers();
        if ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC) {
            System.out.println("访问修饰符是:public");
        } else if ((modifiers & Modifier.PROTECTED) == Modifier.PROTECTED) {
            System.out.println("<访问修饰符是>:protected");
        } else if ((modifiers & Modifier.PRIVATE) == Modifier.PRIVATE) {
            System.out.println("<访问修饰符是>:private");
        } else {
            System.out.println("访问修饰符是 default(package)");
        }
        if ((modifiers & Modifier.STATIC) == Modifier.STATIC) {
            System.out.println("修饰符是:static");
        }
        if ((modifiers & Modifier.FINAL) == Modifier.FINAL) {
            System.out.println("修饰符是:final");
        }
        if ((modifiers & Modifier.ABSTRACT) == Modifier.ABSTRACT) {
            System.out.println("这个类是 abstract的");
        }


        System.out.println("=======构造方法展示=======");
        Constructor[] cons = ps.getDeclaredConstructors();
        for (Constructor c : cons) {
            System.out.println("构造方法名字:" + c.getName());
            System.out.println("参数数量" + c.getParameterCount());
        }

        System.out.println("=======属性展示=======");
        Field[] fields = ps.getDeclaredFields();
        for (Field f : fields) {
            System.out.println("属性名:" + f.getName());
            System.out.println("属性;类型" + f.getType().getName());
        }
        System.out.println("=======方法展示=======");
        Method[] methods = ps.getDeclaredMethods();
        for (Method m : methods) {
            System.out.println("方法名:" + m.getName());
            System.out.println("方法返回值:" + m.getReturnType().getName());
            System.out.println("参数数量" + m.getParameterTypes().length);
        }

    }
}
